<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/7/25
 * Time: 10:20
 */

namespace app\admin\controller;
use JonnyW\PhantomJs\Http\RequestInterface;
use QL\QueryList;
use QL\Ext\PhantomJs;
use think\Controller;


class Ceshi extends Controller
{
    //刀网 活动线报采集
    public function daow()
    {
        //采集规则
        $rules = [
            'title' => array('.post-title a','text'),
            'link' => array('.post-title a','href'),
            'ptime' => array('.ptime span','text'),
        ];
        //第一个参数为从第几页开始，第二个参数为采集几页
        for($i = 1;$i<=2;$i++){
            $url = 'https://www.xd0.com/i_wz.asp?id=306807&PageIndex=' . $i;//$i为页数
            $html = @file_get_contents($url);//获取网页内容并不显示致命错误
            //开始采集
            $data = QueryList::html($html)
                ->encoding('GB2312')
                ->rules($rules)
                ->query()
                ->getData(function($item){
                    $info['title'] = $item['title'];
                    $info['link'] = 'https://www.xd0.com/' . $item['link'];//默认采集下来没有域名部分 重新拼装了一下
                    $info['ptime'] = $item['ptime'];
                    return $info;
                })
                ->all();
            $resAll[$i] = $data;
            print_r($resAll);
        }
    }

    public function index()
    {
    }
}